﻿using System;
using System.Windows.Forms;

namespace WindowsApplication2._7_访问数据.文件.文件编码
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string fName;
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = "";//注意这里写路径时要用c:而不是c:　
            //openFileDialog.Filter = "文本文档|*.txt";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.FilterIndex = 1;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                fName = openFileDialog.FileName;

                textBox1.Text = fName;

                txtBox.Text = System.IO.File.ReadAllText(fName,
                    EncodingType.GetType(fName));
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}